package com.wteam.dragon.model.controller;

import com.wteam.dragon.model.pojo.bean.Role;
import com.wteam.dragon.model.pojo.vo.RoleVo;
import com.wteam.dragon.model.service.RoleService;
import com.wteam.dragon.system.aop.log.log.Log;
import com.wteam.dragon.system.basebean.bean.ResultMessage;
import com.wteam.dragon.system.util.BeanUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

/**
 * @Author 陈晓辉
 * @Date 2020/12/18 10:57
 */
@RestController
@RequestMapping("admin/role")
@Api(tags = "系统：角色管理")
@RequiredArgsConstructor
public class RoleController {
    private final RoleService roleService;

    @Log("添加角色")
    @ApiOperation("添加角色")
    @PostMapping("addRole")
    @PreAuthorize("@el.check('addRole')")
    public ResultMessage addRole(@RequestBody RoleVo roleVo){
        Role role = BeanUtil.from(roleVo, Role.class);
        return roleService.addRole(role);
    }

    @Log("删除角色")
    @ApiOperation("删除角色")
    @DeleteMapping("delRole")
    @PreAuthorize("@el.check('delRole')")
    public ResultMessage delRole(Long roleId){
        return roleService.delRole(roleId);
    }

    @Log("更改角色")
    @ApiOperation("更改角色")
    @PutMapping("editRole")
    @PreAuthorize("@el.check('editRole')")
    public ResultMessage editRole(@RequestBody RoleVo roleVo){
        Role role = BeanUtil.from(roleVo, Role.class);
        return roleService.editRole(role);
    }

    @Log("获得角色列表")
    @ApiOperation("获得角色列表")
    @GetMapping("listRole")
    @PreAuthorize("@el.check('listRole')")
    public ResultMessage listRole(String roleName){
        return roleService.listRole(roleName);
    }

    @Log("获得菜单权限列表树")
    @ApiOperation("获得菜单权限列表树")
    @GetMapping("treeRole")
    @PreAuthorize("@el.check('treeRole')")
    public ResultMessage treeRole(){
        return roleService.treeRole();
    }

    @Log("获得角色详细信息")
    @ApiOperation("获得角色详细信息")
    @GetMapping("getRole")
    @PreAuthorize("@el.check('getRole')")
    public ResultMessage getRole(Long id){
        return roleService.getRole(id);
    }

    @Log("获得当前用户的角色信息")
    @ApiOperation("获得当前用户的角色信息")
    @GetMapping("getCurrentRole")
    @PreAuthorize("@el.check('getCurrentRole')")
    public ResultMessage getCurrentRole(){
        return roleService.getCurrentRole();
    }
}
